//
//  DetailViewController.m
//  HdMovie
//
//  Created by Classic on 1/9/13.
//  Copyright (c) 2013 Hoang tuan. All rights reserved.
//

#import "DetailViewController.h"
#import "MoviePlayViewController.h"

@interface DetailViewController ()

@end

BOOL menuIconShow = NO;

@implementation DetailViewController
@synthesize movie;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
    [_imgCover setImage:[UIImage imageNamed:movie.imgName]];
    [_lblDetail setText:[NSString stringWithFormat:@" %@ \n %d\n %d\n",movie.title, movie.year, movie.like]];
    [_lblDetail setEditable:NO];
    [_btnShare setImage:[UIImage imageNamed:NSLocalizedString(@"btn-share-select", @"btn share")] forState:UIControlStateHighlighted];
    [_btnLike setImage:[UIImage imageNamed:NSLocalizedString(@"btn-like-select", @"btn like")] forState:UIControlStateHighlighted];
    [_btnComment setImage:[UIImage imageNamed:NSLocalizedString(@"btn-comment-select", @"btn comment")] forState:UIControlStateHighlighted];
    [_btnSetting setImage:[UIImage imageNamed:NSLocalizedString(@"btn-setting-select", @"btn setting")] forState:UIControlStateHighlighted];
    [_btnShare setImage:[UIImage imageNamed:NSLocalizedString(@"btn-share-select", @"btn share")] forState:UIControlStateDisabled];
    [_btnSetting setImage:[UIImage imageNamed:NSLocalizedString(@"btn-setting-select", @"btn setting")] forState:UIControlStateDisabled];
    [_rdBtnComment setBackgroundImage:[UIImage imageNamed:@"radio-btn-hightline.png"] forState:UIControlStateDisabled];
    [_rdBtnInfo setBackgroundImage:[UIImage imageNamed:@"radio-btn-hightline.png"] forState:UIControlStateDisabled];
    [_btnRefresh setImage:[UIImage imageNamed:NSLocalizedString(@"btn-refresh-select", @"btn-refresh")] forState:UIControlStateHighlighted];
    
    _txtComment.delegate = self;
    [self menuDetailIconHide];
    [self settingViewHide];
    [self commentHide];
    [_rdBtnInfo setEnabled:NO];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)playClick:(id)sender {
    NSLog(@"play");
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    MoviePlayViewController *moviePlay = [storyboard instantiateViewControllerWithIdentifier:@"MoviePlayViewController"];
    moviePlay.movie = movie;
    [moviePlay setModalPresentationStyle:UIModalPresentationFullScreen];
    moviePlay.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:moviePlay animated:YES];
}

- (IBAction)swipe:(id)sender {
    if (menuIconShow) {
        [self menuDetailIconHide];
        [self settingViewHide];
        
    }else{
        [self menuDetailIconShow];
    }
}

-(void)menuDetailIconShow
{
    CGRect rootViewFrame = self.view.bounds; //lay kich thuoc man hinh
    //animation
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    [UIView setAnimationDuration:0.2];
    [_viewMenu setFrame:CGRectMake(rootViewFrame.size.width - 75, 0, 75, rootViewFrame.size.height)];
    [UIView commitAnimations];
    menuIconShow = YES;
}
-(void)menuDetailIconHide
{
    CGRect rootViewFrame = self.view.bounds; //lay kich thuoc man hinh
    //animation
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    [UIView setAnimationDuration:0.2];
    [_viewMenu setFrame:CGRectMake(rootViewFrame.size.width, 0, 75, rootViewFrame.size.height)];
    [UIView commitAnimations];
    menuIconShow = NO;
    
    [_btnShare setEnabled:YES];
    [_btnSetting setEnabled:YES];
}
-(void)settingViewShow
{
    CGRect rootViewFrame = self.view.bounds; //lay kich thuoc man hinh
    //animation
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    [UIView setAnimationDuration:0.2];
    [_viewSetting setFrame:CGRectMake(0, 0, 245, rootViewFrame.size.height)];
    [UIView commitAnimations];
}
-(void)settingViewHide
{
    CGRect rootViewFrame = self.view.bounds; //lay kich thuoc man hinh
    //animation
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    [UIView setAnimationDuration:0.2];
    [_viewSetting setFrame:CGRectMake(-245, 0, 245, rootViewFrame.size.height)];
    [UIView commitAnimations];
}

-(void)commentShow
{
    CGRect rootViewFrame = self.view.bounds; //lay kich thuoc man hinh
    //animation
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    [UIView setAnimationDuration:0.2];
    [_viewComment setFrame:CGRectMake(0, 0,rootViewFrame.size.width, 250)];
    [UIView commitAnimations];
    [_txtComment select:self];
}
-(void)commentHide
{
    CGRect rootViewFrame = self.view.bounds; //lay kich thuoc man hinh
    //animation
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    [UIView setAnimationDuration:0.2];
    [_viewComment setFrame:CGRectMake(0, -250, rootViewFrame.size.width, 250)];
    [UIView commitAnimations];
}

- (IBAction)backClick:(id)sender {
    [self dismissModalViewControllerAnimated:YES];
}
- (IBAction)shareClick:(id)sender {
    NSLog(@"share");
    [self settingViewHide];
    [_btnShare setEnabled:NO];
    [_btnSetting setEnabled:YES];
}

- (IBAction)likeClick:(id)sender {
    NSLog(@"like");
    [self settingViewHide];
    [self menuDetailIconHide];
}

- (IBAction)commentClick:(id)sender {
    NSLog(@"comment");
    [self settingViewHide];
    [self menuDetailIconHide];
    [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(commentShow) userInfo:nil repeats:NO];
}

- (IBAction)refreshClick:(id)sender {
    NSLog(@"refresh");
    [self settingViewHide];
    [self menuDetailIconHide];
}

- (IBAction)settingClick:(id)sender {
    NSLog(@"setting");
    [self settingViewShow];
    [_btnShare setEnabled:YES];
    [_btnSetting setEnabled:NO];
}
- (void)dealloc {
    [self setLblDetail:nil];
    [self setImgCover:nil];
    [self setLblDetail:nil];
    [self setViewMenu:nil];
    [self setBtnSetting:nil];
    [self setBtnComment:nil];
    [self setBtnLike:nil];
    [self setBtnShare:nil];
    [self setViewSetting:nil];
    [self setBtnComment:nil];
    [self setRdBtnComment:nil];
    [self setTxtComment:nil];
    [self setViewComment:nil];
    [self setBtnRefresh:nil];
    [super dealloc];
}
- (void)viewDidUnload {
    [self setLblDetail:nil];
    [self setImgCover:nil];
    [self setLblDetail:nil];
    [self setViewMenu:nil];
    [self setBtnSetting:nil];
    [self setBtnComment:nil];
    [self setBtnLike:nil];
    [self setBtnShare:nil];
    [self setViewSetting:nil];
    [self setBtnComment:nil];
    [self setRdBtnComment:nil];
    [self setTxtComment:nil];
    [self setViewComment:nil];
    [self setBtnRefresh:nil];
    [super viewDidUnload];
}
- (IBAction)rdBtnInfoClick:(id)sender {
    [_rdBtnInfo setEnabled:NO];
    [_rdBtnComment setEnabled:YES];
}

- (IBAction)rdBtnCommentClick:(id)sender {
    [_rdBtnInfo setEnabled:YES];
    [_rdBtnComment setEnabled:NO];
}

- (IBAction)sendClick:(id)sender {
    [_txtComment resignFirstResponder];
    [self commentHide];
}

- (IBAction)cancelClick:(id)sender {
    [_txtComment resignFirstResponder];
    [self commentHide];
}
@end
